# -*- coding: utf-8 -*-
from scpy.logger import get_logger
import os
import sys
# from crawler.crawler_recruitment_postgres import lagou_job_crawler_postgres,job51_crawler_postgres
from crawler.crawler_recruitment_postgres import main, main_trans_mongo_info, trans_recruitment_info_to_ana

reload(sys)
sys.setdefaultencoding('utf-8')

logger = get_logger(__file__)

CURRENT_PATH = os.path.dirname(__file__)
if CURRENT_PATH:
    CURRENT_PATH = CURRENT_PATH + "/"


def process_with_arg():
    """

    """
    if len(sys.argv) < 2:
        print 'Not enough args'
        sys.exit()
    if sys.argv[1].startswith('--'):
        option = sys.argv[1][2:]
        # fetch sys.argv[1] but without the first two characters
        if option == 'version':
            print 'Version 1.0'
        elif option == 'help':
            print '''
               This program is used for company recruitment process
               Options include:
               --version : Prints the version number
               --help    : Display this help
               --work    : Processing working
                           'crawler' start crawler process
                           'trans' start trans base format to analysis format
                           'mongo' start add mongo info
                  '''
        elif option == 'work':
            process = sys.argv[2]
            if process == 'crawler':
                main()
            elif process == 'trans':
                trans_recruitment_info_to_ana()
            elif process == 'mongo':
                main_trans_mongo_info()
            else:
                print '''
                      work process :%s do not exist
                      '''%str(process)
                sys.exit()
        else:
            print 'Unknown option.'
            sys.exit()
    else:
        print 'No action specified.'
        sys.exit()


if __name__ == '__main__':
    process_with_arg()